<template>
  <div class="home">
    <HeaderTop name="首页" />
    <!-- 轮播图 -->
    <Banner v-model:banner="bannerData" />
    <listModule v-model:list="listData" />
    <div class="hot">
      <a :href="hotWeekData?.url"><img :src="hotWeekData.img?.url" /></a>
    </div>
    <Loading v-model:isShow="show" />
  </div>
</template>

<script setup>
import { getPageId, reqHomeApi } from "@/api/home";
import Banner from "@/components/home/Banner.vue";
import listModule from "@/components/home/listModule.vue";
import Loading from "@/components/loading.vue";
import HeaderTop from "@/components/HeaderTop.vue";
import { ref } from "vue";
import { useStore } from "vuex";
import { setPageId } from "@/util/auth";
const store = useStore();
let show = ref(true); //控制显示隐藏遮罩层
let bannerData = ref("");
let listData = ref("");
let hotWeekData = ref("");
const loadPageid = async () => {
  const result = await getPageId();
  if (result.code == 0) {
    show.value = false;
    store.commit("changePageId", result.data.nav[0].pageId);
    store.commit("changeTeamId", result.data.nav[1].pageId);
    setPageId(result.data.nav[0].pageId);
  } else {
    timer = setTimeout(() => {
      show.value = false;
      Toast("加载失败，请重试！");
    }, 3000);
  }
};
loadPageid();
const loadHome = async () => {
  let pageId = store.state.pageId;
  const result = await reqHomeApi({ pageId });
  if (result.code == 0) {
    show.value = false;
    bannerData.value = result.data.data[0].data;
    listData.value = result.data.data[1].data;
    hotWeekData.value = result.data.data[2].data[0];
  } else {
  }
};
loadHome();

// console.log(banner);
</script>
<style scoped>
.hot {
  box-sizing: border-box;
  width: 100%;
  padding: 0 0.3rem;
}
.hot img {
  width: 100%;
  display: block;
}
</style>
